package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"time"
)
func main() {
	db, err := sql.Open(
		"mysql",
		"root:root@tcp(127.0.0.1:3306)/gogogo?charset=utf8&parseTime=true&loc=Local",
	)
	defer db.Close()
	stmt, err := db.Prepare("INSERT INTO tbl_student (stu_no, name, create_time) VALUES (?, ?, ?)")
	if err != nil {
		log.Println("prepare error.", err)
		return
	}
	res, err := stmt.Exec("20200010003", "李四", time.Now())
	if err != nil {
		log.Println("exec error.", err)
		return
	}
	fmt.Println("res =", res)
	id, _ := res.LastInsertId()
	fmt.Println("id =", id)
	rowsAffected, _ := res.RowsAffected()
	fmt.Println("affectedRows =", rowsAffected)
}
